<template>
	<view>
		{{times}}后标记为已读
	</view>
</template>

<script>
	import {
		getCountDown,
		setCountDown
	} from "../../utils/stroage.js";
	import {
		zeroFun
	} from '../../utils/zero.js'
	export default {
		props: ["bdid", "time"],
		data() {
			return {
				TotalTime: 0,
				isRead:false
			}
		},
		computed: {
			times() {
				let hour = Math.floor(this.TotalTime / 3600)
				let minute = Math.floor(this.TotalTime / 60)
				let second = this.TotalTime % 60
				return zeroFun(hour) + ":" + zeroFun(minute) + ":" + zeroFun(second)
			}
		},
		methods: {
			TimeFun(val) {
				if (this.isRead) {
					this.TotalTime = 0
					uni.showToast({
						icon: 'success',
						title: '标记为已读'
					})
				} else {
					let timer=setInterval(() => {
						if (this.TotalTime == 0) {
							setCountDown(this.bdid)
							uni.showToast({
								icon: 'success',
								title: '标记为已读'
							})
							clearInterval(timer)
							return
						}
						this.TotalTime--
					}, 1000)
				}
			}
		},
		watch: {
			bdid:function(newVal, oldVal){
				const readArr=getCountDown()
				this.isRead=readArr.indexOf(newVal)>-1
			},
			time: function(newVal, oldVal) {
				this.TotalTime=newVal
				this.TimeFun(newVal)
			},
		}
	}
</script>

<style>
</style>
